﻿using System;
using System.ComponentModel;

namespace MyUtils
{
	[Serializable]
	public abstract class Observable : INotifyPropertyChanged
	{
		#region INotifyPropertyChanged Members

		public event PropertyChangedEventHandler PropertyChanged;

		#endregion

		protected void OnPropertyChanged(string name)
		{
			#if DEBUG
			if(!string.IsNullOrEmpty(name))
			{
				if(TypeDescriptor.GetProperties(this)[name] == null)
				{
					throw new Exception("Ivalid property name in OnPropertyChanged");
				}
			}
			#endif

			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(name));
			}
		}
	}
}